home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / storage / ipc / ipci.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  3.8 KB  |  164 lines

  1. /*
  2.  * ipci.c --
  3.  *    POSTGRES inter-process communication initialization code.
  4.  */
  5.  
  6. #include "tmp/c.h"
  7.  
  8. #include "storage/ipc.h"
  9. #include "utils/log.h"
  10. #include "storage/sinval.h"
  11. #include "storage/ipci.h"
  12. #include "storage/bufmgr.h"
  13. #include "storage/lock.h"
  14. #include "tcop/slaves.h"
  15.  
  16. RcsId("$Header: /private/postgres/src/storage/ipc/RCS/ipci.c,v 1.22 1991/08/29 23:54:07 mer Exp $");
  17.  
  18. IPCKey
  19. SystemPortAddressCreateIPCKey(address)
  20.     SystemPortAddress    address;
  21. {
  22.     Assert(address < 32768);    /* XXX */
  23.  
  24.     return (SystemPortAddressGetIPCKey(address));
  25. }
  26.  
  27. /**************************************************
  28.  
  29.   CreateSharedMemoryAndSemaphores
  30.   is called exactly *ONCE* by the postmaster.
  31.   It is *NEVER* called by the postgres backend
  32.  
  33.   0) destroy any existing semaphores for both buffer
  34.      and lock managers.
  35.   1) create the appropriate *SHARED* memory segments
  36.      for the two resource managers.
  37.   
  38.  **************************************************/
  39.  
  40. void
  41. CreateSharedMemoryAndSemaphores(key)
  42.     IPCKey    key;
  43. {
  44.     int        status;
  45.     int        size;
  46.  
  47. #ifdef HAS_TEST_AND_SET
  48.     /* ---------------
  49.      *  create shared memory for slocks
  50.      * --------------
  51.      */
  52.     CreateAndInitSLockMemory(IPCKeyGetSLockSharedMemoryKey(key));
  53. #endif
  54.     /* ----------------
  55.      *    kill and create the buffer manager buffer pool (and semaphore)
  56.      * ----------------
  57.      */
  58.     CreateSpinlocks(IPCKeyGetSpinLockSemaphoreKey(key));
  59.     size = BufferShmemSize() + LockShmemSize();
  60.  
  61. #ifdef SONY_JUKEBOX
  62.     size += SJShmemSize();
  63. #endif /* SONY_JUKEBOX */
  64.  
  65. #ifdef MAIN_MEMORY
  66.     size += MMShmemSize();
  67. #endif /* MAIN_MEMORY */
  68.  
  69.     ShmemCreate(IPCKeyGetBufferMemoryKey(key), size);
  70.     ShmemBindingTabReset();
  71.     InitShmem(key, size);
  72.     InitBufferPool(key);
  73.  
  74.     /* ----------------
  75.      *    create and initialize the executor shared segment (and semaphore)
  76.      * ----------------
  77.      */
  78.     if (key == PrivateIPCKey && ParallelExecutorEnabled()) {
  79.     ExecInitExecutorSemaphore(PrivateIPCKey);
  80.     ExecCreateExecutorSharedMemory(PrivateIPCKey);
  81.     ExecAttachExecutorSharedMemory();
  82.     }
  83.  
  84. #ifdef SONY_JUKEBOX
  85.     /* ----------------
  86.      *    create and initialize the sony jukebox shared semaphore
  87.      * ----------------
  88.      */
  89.     SJInitSemaphore(key);
  90. #endif
  91.  
  92.     /* ----------------
  93.      *    do the lock table stuff
  94.      * ----------------
  95.      */
  96.     InitLocks();
  97.     InitMultiLevelLockm();
  98.     if (InitMultiLevelLockm() == INVALID_TABLEID)
  99.     elog(FATAL, "Couldn't create the lock table");
  100.  
  101.     CreateSharedInvalidationState(key);
  102. }
  103.  
  104.  
  105. void
  106. AttachSharedMemoryAndSemaphores(key)
  107.     IPCKey    key;
  108. {
  109.     int    status;
  110.     int size;
  111.  
  112.     /* ----------------
  113.      *    create rather than attach if using private key
  114.      * ----------------
  115.      */
  116.     if (key == PrivateIPCKey) {
  117.     CreateSharedMemoryAndSemaphores(key);
  118.     return;
  119.     }
  120.  
  121. #ifdef HAS_TEST_AND_SET
  122.     /* ----------------
  123.      *  attach the slock shared memory
  124.      * ----------------
  125.      */
  126.     AttachSLockMemory(IPCKeyGetSLockSharedMemoryKey(key));
  127. #endif
  128.     /* ----------------
  129.      *    attach the buffer manager buffer pool (and semaphore)
  130.      * ----------------
  131.      */
  132.     size = BufferShmemSize() + LockShmemSize();
  133.     InitShmem(key, size);
  134.     InitBufferPool(key);
  135.  
  136.     /* ----------------
  137.      *    create and initialize the executor shared segment (and semaphore)
  138.      * ----------------
  139.      */
  140.     if (ParallelExecutorEnabled()) {
  141.     ExecInitExecutorSemaphore(PrivateIPCKey);
  142.     ExecCreateExecutorSharedMemory(PrivateIPCKey);
  143.     ExecAttachExecutorSharedMemory();
  144.     }
  145.  
  146. #ifdef SONY_JUKEBOX
  147.     /* ----------------
  148.      *    create and initialize the sony jukebox shared semaphore
  149.      * ----------------
  150.      */
  151.     SJInitSemaphore(key);
  152. #endif
  153.  
  154.     /* ----------------
  155.      *    initialize lock table stuff
  156.      * ----------------
  157.      */
  158.     InitLocks();
  159.     if (InitMultiLevelLockm() == INVALID_TABLEID)
  160.     elog(FATAL, "Couldn't attach to the lock table");
  161.  
  162.     AttachSharedInvalidationState(key);
  163. }
  164.